package ecmnext.utils.gui;

/***************************************************************/
/*                     SOFTWARE SECTION                        */
/***************************************************************/
/*
 * <p>Name: ECMNext</p>
 * <p>Description: Simulation of the platform of trading Software</p>
 * <p>Licence: General Public License</p>
 * <p>Organisation: EC Marseille</p>
 * <p>Persons involved in the project : groupe Plateforme de Trading</p>
 * <p>Current version: 1.0</p>
 */


/***************************************************************/
/*                      IMPORT SECTION                         */
/***************************************************************/

import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;

/***************************************************************/
/*            JLabelRenderer INTERFACE SECTION                 */
/***************************************************************/
/**JLabelRenderer
 * <p>Title: JLabelRenderer</p>
 * <p>Description: </p>
 * @author Xuewen YANG ET Antoine COUDERC
 * @version 0.2
 */

public class JLabelRenderer extends JLabel implements TableCellRenderer {
    public JLabelRenderer() {
      setOpaque(true); //MUST do this for background to show up.
    }

    public Component getTableCellRendererComponent(
                            JTable table, Object jLabel,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
      Color newColor;

      String newtext;
      Font newFont;
      if (jLabel != null) {
        newColor = ( (JLabel) jLabel).getBackground();
        newtext = ( (JLabel) jLabel).getText();
        newFont = ((JLabel)jLabel).getFont();
      }
      else {
        newColor = new Color(255,255,255);
        newtext = "";
        newFont = ecmnext.utils.Constants.FONT_DEFAULT_LABEL;
      }
      Color newColor2 = new Color(newColor.getRed(),newColor.getGreen(),newColor.getBlue(),128);
      setBackground(newColor2);
      setText(newtext);
      this.setHorizontalAlignment(this.CENTER);
      this.setVerticalAlignment(this.CENTER);
      this.setFont(newFont);
      return this;
    }
  }
